/*******************
This timer.c file is for STC90C52 MCU 
controlling the fan of some buildings


Functions:
Reading the button status, give the command

*******************/
#include "STC89C51RC_RD_PLUS.H"
#include <intrins.h>
#include "user.h"

#define FOSC 11059200L
#define T1MS (65536-FOSC/12/1000)  //1ms timer calculation in 12T mode

unsigned int  SPEED=75;  //the bigger ,speed is more slow
unsigned int  SPEED_TOTAL=75*4-1;

unsigned int timer_count=0;	 //for fan rotation speed control,
unsigned int timer_count2=0;	//for current setting flash speed control
extern void led_on(void);
extern void led_off(void);
extern unsigned char lcd_flag2;

void timer2_init(void)//timer2 for flash speed control
{
	T2MOD=0;
	T2CON=0;
	RCAP2L=TL2=T1MS;
	RCAP2H=TH2=T1MS>>8;
	TR2=1;
	ET2=1;
	EA=1;
	timer_count=0;

}

//timer2 interrupt routine
void tim2_isr() interrupt 5 using 1
{
	TF2=0;
	timer_count++;
	if(timer_count==SPEED_TOTAL)
	{
		timer_count=0;
		timer_count2++;
			if(timer_count2==7)
				timer_count2=0;	
//		lcd_flag2=1;	
	}
	

}











